## title:   Narcissism in Political Participation
## authors: Z. Fazekas & P.K. Hatemi
## study:   all
## goal:    correlations (for appendix)
## ----

## 0. packages and functions --
library("dplyr")
library("reshape2")
library("ggplot2")
library("ggthemes")
library("psych")
library("polycor")

## 1. load data -- 
## see README.txt for PATH descriptions and assumptions
## note on paths: if working directory is the script's
##                and folder structure is kept
##                paths will work
source("helper.R")
dk11 <- read.csv("./data/dk11-reg.csv")
us13 <- read.csv("./data/us13-reg.csv")
us15 <- read.csv("./data/us15-reg.csv")

## housekeeping to facilitate running all models in one shot
dk11$not_caucasian <- 0  ## constant, as not available, lm drops it
dk11$exhib_sd      <- 0  ## constant, as not available, lm drops it
dk11$exhib         <- NA ## original exhib NA in DK
us15$eff_full      <- 0  ## constant, as not available, lm drops it
names(dk11)[1]     <- "uid" ## same unique id var name in all studies
names(us13)[1]     <- "uid" ## same unique id var name in all studies
names(us15)[1]     <- "uid" ## same unique id var name in all studies

us13$sample_num    <- 1 ## numeric sample ID, only varies for US13 (Mturk)
us13$sample_num[us13$sample == "Wave2"]         <- 2
us13$sample_num[us13$sample == "Oversample"]    <- 3
dk11$sample_num    <- 1 ## constant, as not available, lm drops it
us15$sample_num    <- 1 ## constant, as not available, lm drops it

dk11$turnout_2012 <- dk11$turnout
dk11$turnout_2014 <- 0
us13$turnout_2014 <- 0

## correlation plots/tables

us13$female_fa  <- factor(us13$female)
us13$notcauc_fa <- factor(us13$not_caucasian)
us13$edu_fa     <- factor(us13$edu_cat)
us13$turnout_2012fa  <- factor(us13$turnout_2012)

us15$female_fa  <- factor(us15$female)
us15$notcauc_fa <- factor(us15$not_caucasian)
us15$edu_fa     <- factor(us15$edu_cat)
us15$turnout_2012fa  <- factor(us15$turnout_2012)
us15$turnout_2014fa  <- factor(us15$turnout_2014)

dk11$female_fa  <- factor(dk11$female)
dk11$edu_fa     <- factor(dk11$edu_cat)
dk11$superior   <- factor(dk11$superior)
dk11$vanity     <- factor(dk11$vanity)
dk11$turnout_fa <- factor(dk11$turnout_2012)
dk11$grandexhib <- factor(dk11$grandexhib)

## using hetcor - applies appropriate correlation dep. on var structure
dk11_cor <- 
  hetcor(dk11$npi,
         dk11$authority, 
         dk11$exploit,
         dk11$entitle,
         dk11$sufficient,
         dk11$superior,
         dk11$vanity,
         dk11$leadauth,
         dk11$grandexhib,
         dk11$entexp,
         dk11$female_fa, 
         dk11$edu_fa, 
         dk11$age,
         dk11$part_full,
         dk11$turnout_fa,
         dk11$interest)

us13_cor <- 
  hetcor(us13$npi,
         us13$authority, 
         us13$exploit,
         us13$entitle,
         us13$sufficient,
         us13$superior,
         us13$exhib,
         us13$vanity,
         us13$leadauth,
         us13$grandexhib,
         us13$entexp,        
         us13$female_fa, 
         us13$notcauc_fa, 
         us13$edu_fa, 
         us13$age,
         us13$part_full,
         us13$turnout_2012fa,
         us13$interest)
us15_cor <- 
  hetcor(us15$npi,
         us15$authority, 
         us15$exploit,
         us15$entitle,
         us15$sufficient,
         us15$superior,
         us15$exhib,
         us15$vanity,
         us15$leadauth,
         us15$grandexhib,
         us15$entexp,           
         us15$female_fa, 
         us15$notcauc_fa, 
         us15$edu_fa, 
         us15$age,
         us15$part_full,
         us15$turnout_2012fa,
         us15$turnout_2014fa,
         us15$interest)

## selecting relevant comparisons (outcomes and other correlates)
## both estimates $correlations
## and standard errors
dk11_corval <- cbind(melt(dk11_cor$correlations[11:16, 11:16]),
                     melt(dk11_cor$std.errors[11:16, 11:16]))
us13_corval <- cbind(melt(us13_cor$correlations[12:18, 12:18]),
                     melt(us13_cor$std.errors[12:18, 12:18]))
us15_corval <- cbind(melt(us15_cor$correlations[12:18, 12:18]),
                     melt(us15_cor$std.errors[12:18, 12:18])) 
names(dk11_corval)[c(3, 6)] <- c("r", "r_se")
names(us13_corval)[c(3, 6)] <- c("r", "r_se")
names(us15_corval)[c(3, 6)] <- c("r", "r_se")

dk11_corval$is_sig <- ifelse((abs(dk11_corval$r) - 
                                1.96*dk11_corval$r_se) > 0, 1, 0)
us13_corval$is_sig <- ifelse((abs(us13_corval$r) - 
                                1.96*us13_corval$r_se) > 0, 1, 0)

us15_corval$is_sig <- ifelse((abs(us15_corval$r) - 
                                1.96*us15_corval$r_se) > 0, 1, 0)


dk11_corval <- dk11_corval[, c(1:3, 6:7)] %>% 
  filter(Var2 == "dk11.part_full" | Var2 == "dk11.turnout_fa")
dk11_corval$outcome <- "Participation"
dk11_corval$outcome[dk11_corval$Var2 == "dk11.turnout_fa"] <- "Turnout"

dk11_corval$covariates <- NA
dk11_corval$covariates[dk11_corval$Var1 == "dk11.female_fa"] <- "Female"
dk11_corval$covariates[dk11_corval$Var1 == "dk11.interest"] <- "Interest"
dk11_corval$covariates[dk11_corval$Var1 == "dk11.edu_fa"] <- "Education"
dk11_corval$covariates[dk11_corval$Var1 == "dk11.age"] <- "Age"
table(dk11_corval$covariates, dk11_corval$Var1)

us13_corval <- us13_corval[, c(1:3, 6:7)] %>% 
  filter(Var2 == "us13.part_full" | Var2 == "us13.turnout_2012fa")
us13_corval$outcome <- "Participation"
us13_corval$outcome[us13_corval$Var2 == "us13.turnout_2012fa"] <- "Turnout"

us13_corval$covariates <- NA
us13_corval$covariates[us13_corval$Var1 == "us13.female_fa"] <- "Female"
us13_corval$covariates[us13_corval$Var1 == "us13.interest"] <- "Interest"
us13_corval$covariates[us13_corval$Var1 == "us13.notcauc_fa"] <- "Not caucasian"
us13_corval$covariates[us13_corval$Var1 == "us13.edu_fa"] <- "Education"
us13_corval$covariates[us13_corval$Var1 == "us13.age"] <- "Age"


us15_corval <- us15_corval[, c(1:3, 6:7)] %>% 
  filter(Var2 == "us15.part_full" | Var2 == "us15.turnout_2012fa" |
           Var2 == "us15.turnout_2014fa")

us15_corval$outcome <- "Participation"
us15_corval$outcome[us15_corval$Var2 == "us15.turnout_2012fa"] <- "Turnout"
us15_corval$outcome[us15_corval$Var2 == "us15.turnout_2014fa"] <- "Turnout (2014)"

us15_corval$covariates <- NA
us15_corval$covariates[us15_corval$Var1 == "us15.female_fa"] <- "Female"
us15_corval$covariates[us15_corval$Var1 == "us15.interest"] <- "Interest"
us15_corval$covariates[us15_corval$Var1 == "us15.notcauc_fa"] <- "Not caucasian"
us15_corval$covariates[us15_corval$Var1 == "us15.edu_fa"] <- "Education"
us15_corval$covariates[us15_corval$Var1 == "us15.age"] <- "Age"


ggplot(na.omit(dk11_corval), aes(y        = outcome,
                        x        = covariates,
                        fill     = factor(ifelse(r > 0, 1, 0)))) +
  geom_point(aes(size = abs(r)), shape = 21, colour = "white") + 
  scale_fill_manual("", values = c("#aec2e2", "#f78f6a"), guide = FALSE) +
  scale_size(range = c(8, 22), guide = FALSE) +
  geom_text(data = dk11_corval[dk11_corval$is_sig == 1,], 
            aes(label = paste0(round(r, 2), "*")), size = 3.5) +
  xlab("") +
  ylab("") +
  theme_minimal(base_size = 14) +
  theme(panel.background = element_rect(fill = "grey98", colour = NA)) +
  theme(strip.text = element_text(size = 16),
        axis.text.y = element_text(size = 14),
        axis.text.x = element_text(size = 8),
        panel.grid.major.y = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.grid.major.x = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.spacing = unit(1.5, "lines"),
        axis.title.x = element_text(size  = 10, hjust = 1, vjust = 0),
        plot.margin = unit(c(1,1,1,1), "cm"))

ggplot(na.omit(us13_corval), aes(y        = outcome,
                                 x        = covariates,
                                 fill     = factor(ifelse(r > 0, 1, 0)))) +
  geom_point(aes(size = abs(r)), shape = 21, colour = "white") + 
  scale_fill_manual("", values = c("#aec2e2", "#f78f6a"), guide = FALSE) +
  scale_size(range = c(8, 22), guide = FALSE) +
  geom_text(data = us13_corval[us13_corval$is_sig == 1,], 
            aes(label = paste0(round(r, 2), "*")), size = 3.5) +
  xlab("") +
  ylab("") +
  theme_minimal(base_size = 14) +
  theme(panel.background = element_rect(fill = "grey98", colour = NA)) +
  theme(strip.text = element_text(size = 16),
        axis.text.y = element_text(size = 14),
        axis.text.x = element_text(size = 8),
        panel.grid.major.y = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.grid.major.x = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.spacing = unit(1.5, "lines"),
        axis.title.x = element_text(size  = 10, hjust = 1, vjust = 0),
        plot.margin = unit(c(1,1,1,1), "cm"))


ggplot(na.omit(us15_corval), aes(y        = outcome,
                                 x        = covariates,
                                 fill     = factor(ifelse(r > 0, 1, 0)))) +
  geom_point(aes(size = abs(r)), shape = 21, colour = "white") + 
  scale_fill_manual("", values = c("#aec2e2", "#f78f6a"), guide = FALSE) +
  scale_size(range = c(8, 22), guide = FALSE) +
  geom_text(data = us15_corval[us15_corval$is_sig == 1,], 
            aes(label = paste0(round(r, 2), "*")), size = 3.5) +
  xlab("") +
  ylab("") +
  theme_minimal(base_size = 14) +
  theme(panel.background = element_rect(fill = "grey98", colour = NA)) +
  theme(strip.text = element_text(size = 16),
        axis.text.y = element_text(size = 14),
        axis.text.x = element_text(size = 8),
        panel.grid.major.y = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.grid.major.x = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.spacing = unit(1.5, "lines"),
        axis.title.x = element_text(size  = 10, hjust = 1, vjust = 0),
        plot.margin = unit(c(1,1,1,1), "cm"))



## selecting relevant comparisons (outcomes and narcissism)
## both estimates $correlations
## and standard errors

dk11_corval <- cbind(melt(dk11_cor$correlations[1:10, 11:16]),
                     melt(dk11_cor$std.errors[1:10, 11:16]))
us13_corval <- cbind(melt(us13_cor$correlations[1:11, 12:18]),
                     melt(us13_cor$std.errors[1:11, 12:18]))
us15_corval <- cbind(melt(us15_cor$correlations[1:11, 12:18]),
                          melt(us15_cor$std.errors[1:11, 12:18])) 

names(dk11_corval)[c(3, 6)] <- c("r", "r_se")
names(us13_corval)[c(3, 6)] <- c("r", "r_se")
names(us15_corval)[c(3, 6)] <- c("r", "r_se")

## are they significant correlations (used in plot color)
dk11_corval$is_sig <- ifelse((abs(dk11_corval$r) - 
                                  1.96*dk11_corval$r_se) > 0, 1, 0)
us13_corval$is_sig <- ifelse((abs(us13_corval$r) - 
                                  1.96*us13_corval$r_se) > 0, 1, 0)

us15_corval$is_sig <- ifelse((abs(us15_corval$r) - 
                                  1.96*us15_corval$r_se) > 0, 1, 0)

## meaningful names for all entries
dk11_corval$outcome <- "Participation"
dk11_corval$outcome[dk11_corval$Var2 == "dk11.turnout_fa"] <- "Turnout"
dk11_corval$outcome[dk11_corval$Var2 == "dk11.interest"] <- "Interest"
dk11_corval$outcome[dk11_corval$Var2 == "dk11.female_fa"] <- "Female"
dk11_corval$outcome[dk11_corval$Var2 == "dk11.edu_fa"] <- "Education"
dk11_corval$outcome[dk11_corval$Var2 == "dk11.age"] <- "Age"

dk11_corval$narcissism <- "Narcissism (full NPI)"
dk11_corval$narcissism[dk11_corval$Var1 == "dk11.authority"] <- 
    "Authority"
dk11_corval$narcissism[dk11_corval$Var1 == "dk11.entitle"] <- 
    "Entitlement"
dk11_corval$narcissism[dk11_corval$Var1 == "dk11.exploit"] <- 
    "Exploitativeness"
dk11_corval$narcissism[dk11_corval$Var1 == "dk11.superior"] <- 
    "Superiority"
dk11_corval$narcissism[dk11_corval$Var1 == "dk11.sufficient"] <- 
    "Self-sufficiency"
dk11_corval$narcissism[dk11_corval$Var1 == "dk11.vanity"] <- 
    "Vanity"
dk11_corval$narcissism[dk11_corval$Var1 == "dk11.leadauth"] <- 
  "Leadership/\nAuthority"
dk11_corval$narcissism[dk11_corval$Var1 == "dk11.grandexhib"] <- 
  "Grandiose\nExhibitionism"
dk11_corval$narcissism[dk11_corval$Var1 == "dk11.entexp"] <- 
  "Entitlement/\nExploitativeness"

## ordering the labels
dk11_corval$outcome <- factor(dk11_corval$outcome, 
                                levels = c("Female",
                                           "Education",
                                           "Age",
                                           "Participation",
                                           "Turnout",
                                           "Interest"))
dk11_corval$narcissism <- factor(dk11_corval$narcissism, 
                                levels = c("Narcissism (full NPI)",
                                           "Authority",
                                           "Superiority",
                                           "Exploitativeness",
                                           "Entitlement",
                                           "Self-sufficiency",
                                           "Vanity",
                                           "Leadership/\nAuthority",
                                           "Grandiose\nExhibitionism",
                                           "Entitlement/\nExploitativeness"))



us13_corval$outcome <- "Participation"
us13_corval$outcome[us13_corval$Var2 == "us13.turnout_2012fa"] <- "Turnout (2012)"
us13_corval$outcome[us13_corval$Var2 == "us13.disc"] <- "Discussion"
us13_corval$outcome[us13_corval$Var2 == "us13.eff_full"] <- "Efficacy"
us13_corval$outcome[us13_corval$Var2 == "us13.interest"] <- "Interest"
us13_corval$outcome[us13_corval$Var2 == "us13.female_fa"] <- "Female"
us13_corval$outcome[us13_corval$Var2 == "us13.edu_fa"] <- "Education"
us13_corval$outcome[us13_corval$Var2 == "us13.notcauc_fa"] <- "Not caucasian"
us13_corval$outcome[us13_corval$Var2 == "us13.age"] <- "Age"

us13_corval$narcissism <- "Narcissism (full NPI)"
us13_corval$narcissism[us13_corval$Var1 == "us13.authority"] <- 
    "Authority"
us13_corval$narcissism[us13_corval$Var1 == "us13.entitle"] <- 
    "Entitlement"
us13_corval$narcissism[us13_corval$Var1 == "us13.exploit"] <- 
    "Exploitativeness"
us13_corval$narcissism[us13_corval$Var1 == "us13.superior"] <- 
    "Superiority"
us13_corval$narcissism[us13_corval$Var1 == "us13.sufficient"] <- 
    "Self-sufficiency"
us13_corval$narcissism[us13_corval$Var1 == "us13.vanity"] <- 
    "Vanity"
us13_corval$narcissism[us13_corval$Var1 == "us13.exhib"] <- 
    "Exhibitionism"
us13_corval$narcissism[us13_corval$Var1 == "us13.leadauth"] <- 
  "Leadership/\nAuthority"
us13_corval$narcissism[us13_corval$Var1 == "us13.grandexhib"] <- 
  "Grandiose\nExhibitionism"
us13_corval$narcissism[us13_corval$Var1 == "us13.entexp"] <- 
  "Entitlement/\nExploitativeness"

## ordering the labels
us13_corval$outcome <- factor(us13_corval$outcome, 
                                levels = c("Female",
                                           "Education",
                                           "Age",
                                           "Not caucasian",
                                           "Participation",
                                           "Turnout (2012)",
                                           "Discussion",
                                           "Efficacy",
                                           "Interest"))
us13_corval$narcissism <- factor(us13_corval$narcissism, 
                                levels = c("Narcissism (full NPI)",
                                           "Authority",
                                           "Superiority",
                                           "Exploitativeness",
                                           "Entitlement",
                                           "Self-sufficiency",
                                           "Exhibitionism",
                                           "Vanity",
                                           "Leadership/\nAuthority",
                                           "Grandiose\nExhibitionism",
                                           "Entitlement/\nExploitativeness"))

us15_corval$outcome <- "Participation"
us15_corval$outcome[us15_corval$Var2 == "us15.turnout_2012fa"] <- "Turnout (2012)"
us15_corval$outcome[us15_corval$Var2 == "us15.turnout_2014fa"] <- "Turnout (2014)"
us15_corval$outcome[us15_corval$Var2 == "us15.disc"] <- "Discussion"
us15_corval$outcome[us15_corval$Var2 == "us15.interest"] <- "Interest"
us15_corval$outcome[us15_corval$Var2 == "us15.female_fa"] <- "Female"
us15_corval$outcome[us15_corval$Var2 == "us15.edu_fa"] <- "Education"
us15_corval$outcome[us15_corval$Var2 == "us15.notcauc_fa"] <- "Not caucasian"
us15_corval$outcome[us15_corval$Var2 == "us15.age"] <- "Age"

us15_corval$Var1
us15_corval$narcissism <- "Narcissism (full NPI)"
us15_corval$narcissism[us15_corval$Var1 == "us15.authority"] <- 
    "Authority"
us15_corval$narcissism[us15_corval$Var1 == "us15.entitle"] <- 
    "Entitlement"
us15_corval$narcissism[us15_corval$Var1 == "us15.exploit"] <- 
    "Exploitativeness"
us15_corval$narcissism[us15_corval$Var1 == "us15.superior"] <- 
    "Superiority"
us15_corval$narcissism[us15_corval$Var1 == "us15.sufficient"] <- 
    "Self-sufficiency"
us15_corval$narcissism[us15_corval$Var1 == "us15.vanity"] <- 
    "Vanity"
us15_corval$narcissism[us15_corval$Var1 == "us15.exhib"] <- 
    "Exhibitionism"
us15_corval$narcissism[us15_corval$Var1 == "us15.leadauth"] <- 
  "Leadership/\nAuthority"
us15_corval$narcissism[us15_corval$Var1 == "us15.grandexhib"] <- 
  "Grandiose\nExhibitionism"
us15_corval$narcissism[us15_corval$Var1 == "us15.entexp"] <- 
  "Entitlement/\nExploitativeness" 

## ordering the labels
us15_corval$outcome <- factor(us15_corval$outcome, 
                                levels = c("Female",
                                           "Education",
                                           "Age",
                                           "Not caucasian",
                                           "Participation",
                                           "Turnout (2012)",
                                           "Turnout (2014)",
                                           "Discussion",
                                           "Interest"))
us15_corval$narcissism <- factor(us15_corval$narcissism, 
                                levels = c("Narcissism (full NPI)",
                                           "Authority",
                                           "Superiority",
                                           "Exploitativeness",
                                           "Entitlement",
                                           "Self-sufficiency",
                                           "Exhibitionism",
                                           "Vanity",
                                           "Leadership/\nAuthority",
                                           "Grandiose\nExhibitionism",
                                           "Entitlement/\nExploitativeness"))

## heat map for correlations in Denmark
dk11_corval$Var1 <- NULL
dk11_corval$Var2 <- NULL

us13_corval$Var1 <- NULL
us13_corval$Var2 <- NULL

us15_corval$Var1 <- NULL
us15_corval$Var2 <- NULL


ggplot(dk11_corval, aes(y        = outcome,
                        x        = narcissism,
                        fill     = factor(ifelse(r > 0, 1, 0)))) +
  geom_point(aes(size = abs(r)), shape = 21, colour = "white") + 
  scale_fill_manual("", values = c("#aec2e2", "#f78f6a"), guide = FALSE) +
  scale_size(range = c(8, 22), guide = FALSE) +
  geom_text(data = dk11_corval[dk11_corval$is_sig == 1,], 
            aes(label = paste0(round(r, 2), "*")), size = 3.5) +
  xlab("") +
  ylab("") +
  theme_minimal(base_size = 14) +
  theme(panel.background = element_rect(fill = "grey98", colour = NA)) +
  theme(strip.text = element_text(size = 16),
        axis.text.y = element_text(size = 14),
        axis.text.x = element_text(size = 8),
        panel.grid.major.y = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.grid.major.x = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.spacing = unit(1.5, "lines"),
        axis.title.x = element_text(size  = 10, hjust = 1, vjust = 0),
        plot.margin = unit(c(1,1,1,1), "cm"))


## heat map for correlations in US 2013
ggplot(us13_corval, aes(y        = outcome,
                        x        = narcissism,
                        fill     = factor(ifelse(r > 0, 1, 0)))) +
  geom_point(aes(size = abs(r)), shape = 21, colour = "white") + 
  scale_fill_manual("", values = c("#aec2e2", "#f78f6a"), guide = FALSE) +
  scale_size(range = c(8, 22), guide = FALSE) +
  geom_text(data = us13_corval[us13_corval$is_sig == 1,], 
            aes(label = paste0(round(r, 2), "*")), size = 3.5) +
  xlab("") +
  ylab("") +
  theme_minimal(base_size = 14) +
  theme(panel.background = element_rect(fill = "grey98", colour = NA)) +
  theme(strip.text = element_text(size = 16),
        axis.text.y = element_text(size = 14),
        axis.text.x = element_text(size = 8),
        panel.grid.major.y = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.grid.major.x = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.spacing = unit(1.5, "lines"),
        axis.title.x = element_text(size  = 10, hjust = 1, vjust = 0),
        plot.margin = unit(c(1,1,1,1), "cm"))


## heat map for correlations in US 2015
ggplot(us15_corval, aes(y        = outcome,
                        x        = narcissism,
                        fill     = factor(ifelse(r > 0, 1, 0)))) +
  geom_point(aes(size = abs(r)), shape = 21, colour = "white") + 
  scale_fill_manual("", values = c("#aec2e2", "#f78f6a"), guide = FALSE) +
  scale_size(range = c(8, 22), guide = FALSE) +
  geom_text(data = us15_corval[us15_corval$is_sig == 1,], 
            aes(label = paste0(round(r, 2), "*")), size = 3.5) +
  xlab("") +
  ylab("") +
  theme_minimal(base_size = 14) +
  theme(panel.background = element_rect(fill = "grey98", colour = NA)) +
  theme(strip.text = element_text(size = 16),
        axis.text.y = element_text(size = 14),
        axis.text.x = element_text(size = 8),
        panel.grid.major.y = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.grid.major.x = element_line(colour = "grey90", size = 0.2, linetype = 2),
        panel.spacing = unit(1.5, "lines"),
        axis.title.x = element_text(size  = 10, hjust = 1, vjust = 0),
        plot.margin = unit(c(1,1,1,1), "cm"))


# R version 3.5.1 (2018-07-02)
# Platform: x86_64-apple-darwin15.6.0 (64-bit)
# Running under: macOS  10.15.4
# 
# Matrix products: default
# BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
# LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
# 
# locale:
#   [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] polycor_0.7-9  psych_1.8.12   ggthemes_4.0.1 ggplot2_3.2.1  reshape2_1.4.3 dplyr_0.8.3   
# 
# loaded via a namespace (and not attached):
#   [1] Rcpp_1.0.2       rstudioapi_0.10  magrittr_1.5     mnormt_1.5-5     tidyselect_0.2.5 munsell_0.5.0    lattice_0.20-35 
# [8] colorspace_1.4-1 R6_2.4.0         rlang_0.4.2      stringr_1.4.0    plyr_1.8.4       tools_3.5.1      parallel_3.5.1  
# [15] grid_3.5.1       nlme_3.1-137     gtable_0.3.0     withr_2.1.2      yaml_2.2.0       lazyeval_0.2.2   assertthat_0.2.1
# [22] tibble_2.1.3     crayon_1.3.4     Matrix_1.2-14    purrr_0.3.3      glue_1.3.1       stringi_1.4.3    compiler_3.5.1  
# [29] pillar_1.4.2     scales_1.0.0     mvtnorm_1.0-8    foreign_0.8-70   pkgconfig_2.0.3 